<?php

namespace app\common\model;

use think\Db;
use think\Model;
use think\Validate;
/**
 *  Address 添加用户地址 模型
 * Class Typeattr
 * @package app\common\model
 */
class Address extends Model
{
    //类型taid
    protected $pk = 'uaid';
    //获取当前的数据表
    protected $table='shop_address';
    //添加
    public function add($data)
    {
        //执行验证，填充数据 save（$data）: $post
        $result = $this->validate(true)->save($data);
        if(false === $result){
            //错误信息
            return ['valid'=>0,'msg'=>$this->getError()];
        }else{
            //成功信息
            return ['valid'=>1,'msg'=>'添加成功'];
        }
    }
    //类型属性的删除
    public function del($taid)
    {
        $result =  Db::table('shop_type_attr')->where('taid',$taid)->delete();
        if(false === $result){
            // 验证失败 输出错误信息
            return ['valid'=>0,'msg'=>$this->getError()];
            //dump($this->getError());
        }else{
            return ['valid'=>1,'msg'=>'删除成功'];
        }
    }
    //类型属性的编辑
    //编辑类型
    public function edit($data)
    {
//        p($data);die;
        $result = $this->validate(true)->save($data,[$this->pk=>$data['taid']]);
//        p($result);die;
        if($result)
        {
            //执行成功
            return ['valid'=>1,'msg'=>'编辑成功'];
        }else{
            return ['valid'=>0,'msg'=>$this->getError()];
        }
    }
}
